package com.zhixinhuixue.zsyte.xxx.ui.activity

import android.os.Bundle
import com.zhixinhuixue.zsyte.xxx.app.base.BaseNewActivity
import com.zhixinhuixue.zsyte.xxx.databinding.ActivityMainBinding
import com.zhixinhuixue.zsyte.xxx.ui.adapter.MainAdapter
import com.zhixinhuixue.zsyte.xxx.ui.viewmodel.TestViewModel
import com.zhixinhuixue.zsyte.xxx.R
import android.view.MenuItem


/**
 * 作者　: hegaojian
 * 时间　: 2020/11/6
 * 描述　:
 */
class MainActivity : BaseNewActivity<TestViewModel, ActivityMainBinding>() {
    override fun initView(savedInstanceState: Bundle?) {
        mToolbar.setCenterTitle(R.string.bottom_title_read)
        mViewBinding.mainViewPager.adapter = MainAdapter(this)
        mViewBinding.mainViewPager.offscreenPageLimit = mViewBinding.mainViewPager.adapter!!.itemCount
        mViewBinding.mainViewPager.isUserInputEnabled = false
        mViewBinding.mainNavigation.itemIconTintList = null;
        resetToDefaultIcon()
        mViewBinding.mainNavigation.setOnNavigationItemSelectedListener { item ->
            when (item.itemId) {
                R.id.navigationRead -> {
                    resetToDefaultIcon()
                    mViewBinding.mainViewPager.setCurrentItem(0, false)
                }
                R.id.navigationUser -> {
                    resetMeDefaultIcon()
                    mViewBinding.mainViewPager.setCurrentItem(3, false)
                }
            }
            true
        }
    }
    private fun resetToDefaultIcon() {
        val home: MenuItem =   mViewBinding.mainNavigation.getMenu().findItem(R.id.navigationRead)
        home.setIcon(R.mipmap.tab_gzt_set)
        val me: MenuItem =   mViewBinding.mainNavigation.getMenu().findItem(R.id.navigationUser)
        me.setIcon(R.mipmap.tab_wd_unset)
    }

    private fun resetMeDefaultIcon() {
        val home: MenuItem =   mViewBinding.mainNavigation.getMenu().findItem(R.id.navigationRead)
        home.setIcon(R.mipmap.tab_gzt_unset)
        val me: MenuItem =   mViewBinding.mainNavigation.getMenu().findItem(R.id.navigationUser)
        me.setIcon(R.mipmap.tab_wd_set)
    }

    override fun showToolBar() = false


}
